home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / GRAPHICS.SWG / 0145_Mode-X Raw Image Put.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  3KB  |  101 lines

  1. {
  2. > I need to put a 64k Raw Image onto Page 0 in 320x200 X-Mode.
  3.  
  4. Well, that wasn't too hard. Faster then the following one doesn't seem
  5. possible. Don't try to make the f_bufsize too large: it'll probably hang your
  6. computer and it won't speed up the picture display. You could, however, set the
  7. palette to all black when displaying the picture, and when it's ready, set the
  8. colors of the picture correctly.
  9.  
  10. You can alter the offsets of the palette and the picture as you like. The
  11. defaults are for the ColoRIX/EGA Paint format, converted with VPic.
  12. }
  13. {$a+,b-,d+,e+,f-,g+,i+,l+,n-,o-,p-,q-,r-,s+,t-,v+,x+} { tp7.0 directives }
  14. {$m 16384,0,655360}
  15.  
  16. program putmodexpicture;
  17. { Display raw picture in mode-x (320x200x256x4), by Bas van Gaalen,
  18.   fido 2:285/213.8, email bas.van.gaalen@schotman.nl, Aug. '94 }
  19.  
  20. uses
  21.   crt,dos;                   { crt for keypressed, dos for pathstr }
  22.  
  23. const
  24.   pal_offset=$000a;          { offset of palette in pic-file }
  25.   pic_offset=$030a;          { offset of picture in pic-file }
  26.   f_bufsize=4096;            { file-buffer size }
  27.   vidseg:word=$a000;         { VGA graphics segment }
  28.  
  29. type
  30.   errmsg=string[80];
  31.   f_buf=array[0..f_bufsize-1] of byte;
  32.   pal_buf=array[0..$2ff] of byte;
  33.  
  34. var
  35.   p_file:file;
  36.  
  37. procedure error(err:errmsg); begin writeln; writeln(err); halt(1); end;
  38.  
  39. procedure setpal(c,r,g,b:byte); assembler; asm
  40.   mov dx,3c8h; mov al,[c]; out dx,al; inc dx; mov al,[r]
  41.   out dx,al; mov al,[g]; out dx,al; mov al,[b]; out dx,al; end;
  42.  
  43. procedure setmodex; assembler; asm
  44.   mov ax,13h; int 10h; mov dx,3c4h; mov ax,0604h; out dx,ax; mov ax,0f02h
  45.   out dx,ax; mov cx,320*200; mov es,vidseg; xor ax,ax; mov di,ax; rep stosw
  46.   mov dx,3d4h; mov ax,0014h; out dx,ax; mov ax,0e317h; out dx,ax; end;
  47.  
  48. procedure putpixel(offs:word; col:byte); assembler; asm
  49.   mov dx,03c4h; mov al,2; mov cx,[offs]; and cx,3; mov ah,1; shl ah,cl
  50.   out dx,ax; mov es,vidseg; mov ax,[offs]; shr ax,2; mov di,ax
  51.   mov al,[col]; mov [es:di],al; end;
  52.  
  53. procedure retrace; assembler; asm
  54.   mov dx,3dah; @vert1: in al,dx; test al,8; jz @vert1
  55.   @vert2: in al,dx; test al,8; jnz @vert2; end;
  56.  
  57. procedure initfile(filename:pathstr);
  58. begin
  59.   if filename='' then error('Enter raw-picture filename on commandline.');
  60.   assign(p_file,filename);
  61.   {$i-} reset(p_file,1); {$i+}
  62.   if ioresult<>0 then error(fexpand(filename)+' not found.');
  63. end;
  64.  
  65. procedure initpal;
  66. var buf:pal_buf; c:word; i:byte;
  67. begin
  68.   seek(p_file,pal_offset);
  69.   blockread(p_file,buf,$300);
  70.   setmodex;
  71.   c:=0;
  72.   for i:=0 to 255 do begin
  73.     setpal(i,buf[c],buf[c+1],buf[c+2]);
  74.     inc(c,3);
  75.   end;
  76. end;
  77.  
  78. procedure displaypic;
  79. var buf:f_buf; i,bufidx:word; nofread:integer;
  80. begin
  81.   bufidx:=0;
  82.   repeat
  83.     blockread(p_file,buf,f_bufsize,nofread);
  84.     for i:=0 to nofread do putpixel(bufidx+i,buf[i]);
  85.     inc(bufidx,nofread);
  86.   until nofread<>f_bufsize;
  87.   close(p_file);
  88. end;
  89.  
  90. var dummy:byte;
  91. begin
  92.   initfile(paramstr(1));
  93.   initpal;
  94.   port[$03c0]:=0; { screen blanck }
  95.   displaypic;
  96.   retrace; dummy:=port[$03da]; port[$03c0]:=32; { show screen }
  97.   repeat until keypressed;
  98.   asm mov ax,3; int 10h; end;
  99. end.
  100.  
  101.